<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
var numSubarrayBoundedMax = function (nums, left, right) {
    let answer = 0;
    let l1 = -1,l2 = -1;
    const n = nums.length
    for (let i = 0; i < n; i++) {
        if(nums[i]>right){ // 遇到分割线了，重置一下
            l1 = -1;
            l2 = i; 
        }else if(nums[i]>=left){
            l1 = i;
        }
        if(l1!==-1){
            answer += (l1 - l2);// 最主要的一步，因为要求子数组连续，如果l1不为1，就表示从当前这个数开始一直到分割线处的子数组都是复合条件的
            console.log(answer);
        }
    }
    return answer;
};
console.log(numSubarrayBoundedMax([2,1,4,3],2,3));
  </script>
</body>
</html>